![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
abstract-extension
Advanced tools
Small abstraction to help build out user defined extension messages in an RPC system
Small abstraction to help build out user defined extension messages in an RPC system.
npm install abstract-extension
See hypercore and hypercore-protocol for a full example on how to use this
const AbstractExtension = require('abstract-extension')
Imports the AbstractExtension class. You should extend this and add the functionality you need.
abstractExtension.destroy()
Detroy an extension instance. Removes the message from the local pairing instance.
abstractExtension.id
The local id of the message. Send this over the wire instead of the message name after exchanging the initial message names.
const bool = abstractExtension.remoteSupports()
True if the remote also supports this message. Note that nothing bad will having from sending a message the remote does not support.
const buffer = abstractExtension.encode(message)
Encode a message to a buffer based on the message encoding.
const local = AbstractExtension.createLocal(handlers)
Create a local message pairing instance.
Whenever the messages are updated local.onextensionupdate()
will be called if provided.
const msg = local.add(name, handlers)
Add a new message. name
should be the string name of a message.
handlers.encoding
is an optional encoding for the message payload. Can be either json
, utf-8
, binary
or any abstract encoding.handlers.onmessage(message, context)
is called when a message has been received and pairing.handlers.onerror(error, context)
is called when a message fails to decode.const list = local.names()
Returns a sorted list of message names. You need to pass this to another remote pairing instance somehow.
const remote = local.remote()
Call this to setup remote pairing.
remote.update(localNames)
Pass the names of another instance to setup the pairing
remote.onmessage(id, message, [context])
Pair the remote id with the corresponding local message and call the onmessage handler.
Optionally pass a context object that is simply passed along to the message.onmessage
function
MIT
FAQs
Small abstraction to help build out user defined extension messages in an RPC system
The npm package abstract-extension receives a total of 145 weekly downloads. As such, abstract-extension popularity was classified as not popular.
We found that abstract-extension demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.